﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DuncanDAL;
using BLL.BaseDictionaryService;

namespace BLL
{
    /// <summary>
    /// 查询所有消费记录业务对象
    /// </summary>
    public class QueryPayRecordsTransaction:ICommand
    {
        protected IList<T_PayRecordsObject> payRecords;

        protected virtual IList<T_PayRecordsObject> PayRecords
        {
            get { return payRecords; }
        }

        #region ICommand 成员

        public void Execute()
        {
            PayRecordsDataService objPayRecordsDataService = new PayRecordsDataService();
            payRecords = objPayRecordsDataService.QueryAll();
            QueryUsersTransaction objQueryUsersTransaction = new QueryUsersTransaction();
            QueryPayNecessityTransaction objQueryPayNecessityTransaction = new QueryPayNecessityTransaction();
            QueryPayCategoryTransaction objQueryPayCategoryTransaction = new QueryPayCategoryTransaction();
            
            objQueryUsersTransaction.Execute();
            IList<T_UserObject> users = objQueryUsersTransaction.Users;

            objQueryPayNecessityTransaction.Execute();
            IList<D_PayNecessityObject> payNecessitys =objQueryPayNecessityTransaction.PayNecessitys;

            objQueryPayCategoryTransaction.Execute();
            IList<D_PayCategoryObject> payCategorys = objQueryPayCategoryTransaction.PayCategorys;

            foreach (T_PayRecordsObject item in payRecords)
            {
                item.UserNickName = users.SingleOrDefault(x => x.Db_OID == item.Db_PayObject).Db_NickName;
                item.PayCategory = payCategorys.SingleOrDefault(x => x.Db_OID == item.Db_PayCategoryOID).Db_CategoryName;
                item.PayNecessity = payNecessitys.SingleOrDefault(x => x.Db_OID == item.Db_PayNecessity).Db_PayNecessity;
            }
        }

        #endregion
    }
}
